import 'package:flutter/material.dart';

class RaisedButtonPage extends StatefulWidget {
  RaisedButtonPage({Key key}) : super(key: key);

  @override
  _RaisedButtonPageState createState() => _RaisedButtonPageState();
}

class _RaisedButtonPageState extends State<RaisedButtonPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("按钮页面"),
        actions: <Widget>[IconButton(icon: Icon(Icons.home), onPressed: () {})],
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(
          Icons.add,
          size: 40,
          color: Colors.white,
        ),
        onPressed: () {
          print("浮动按钮");
        },
        backgroundColor: Colors.orange,
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                child: RaisedButton(
                  child: Text("普通按钮"),
                  color: Colors.blue,
                  textColor: Colors.white,
                  elevation: 8.0,
                  onPressed: () {
                    print("普通按钮");
                  },
                ),
              ),
              SizedBox(width: 10),
              Container(
                child: RaisedButton.icon(
                  label: Text("带头标按钮"),
                  icon: Icon(Icons.home),
                  color: Colors.blue,
                  textColor: Colors.white,
                  elevation: 8.0,
                  onPressed: () {
                    print("带头标按钮");
                  },
                ),
              )
            ],
          ),
          Row(
            children: <Widget>[
              Expanded(
                  child: Container(
                margin: EdgeInsets.all(10),
                height: 50,
                child: RaisedButton(
                  child: Text("自适应按钮"),
                  color: Colors.blue,
                  textColor: Colors.white,
                  elevation: 8.0,
                  onPressed: () {
                    print("自适应按钮");
                  },
                ),
              ))
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              RaisedButton(
                child: Text("圆角按钮"),
                color: Colors.blue,
                textColor: Colors.white,
                elevation: 8.0,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(8)),
                onPressed: () {
                  print("圆角按钮");
                },
              ),
              Container(
                height: 80,
                child: RaisedButton(
                  child: Text("圆形按钮"),
                  color: Colors.blue,
                  textColor: Colors.white,
                  splashColor: Colors.orange, //水波纹
                  elevation: 8.0,
                  shape: CircleBorder(side: BorderSide(color: Colors.white)),
                  onPressed: () {
                    print("圆形按钮");
                  },
                ),
              ),
              FlatButton(
                child: Text("FlatButton"),
                color: Colors.blue,
                textColor: Colors.white,
                onPressed: () {
                  print("FlatButton");
                },
              ),
            ],
          ),
          Row(
            children: <Widget>[
              OutlineButton(
                child: Text("OutlineButton"),
                textColor: Colors.blue,
                onPressed: () {
                  print("OutlineButton");
                },
              )
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ButtonBar(
                children: <Widget>[
                  RaisedButton(
                    child: Text("登录"),
                    onPressed: () {},
                  ),
                  RaisedButton(
                    child: Text("注册"),
                    onPressed: () {},
                  ),
                  MyButton(
                    text: "自定义按钮",
                    width: 100.0,
                    height: 50.0,
                    pressed: () {
                      print("自定义按钮");
                    },
                  )
                ],
              )
            ],
          )
        ],
      ),
    );
  }
}

//自定义按钮
class MyButton extends StatefulWidget {
  final text;
  final pressed;
  final width;
  final height;
  MyButton(
      {this.text = '',
      this.pressed = null,
      this.width = 80.0,
      this.height = 40.0});

  @override
  _MyButtonState createState() => _MyButtonState();
}

class _MyButtonState extends State<MyButton> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: widget.width,
      height: widget.height,
      child: RaisedButton(
        child: Text(widget.text),
        onPressed: widget.pressed,
      ),
    );
  }
}
